<?php

/**
 * 编辑专辑 
 * 
 * @author zhangchao
 * @since 2012-05-15
 */


include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/core/admin.inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/foodv2/inc.php");

$g_cgival = array();
$g_pro = array();
$g_show = array();


function check_cgi_pro()
{
	global $g_cgival, $g_pro, $g_show;
	
	cgi::both($g_cgival['album_id'], 'album_id', 0);
	$g_cgival['album_id'] = intval($g_cgival['album_id']);
	if($g_cgival['album_id'] <= 0)
	{
		throw new Exception('album_id不合法');
	}
	
}

function get_data()
{
	global $g_cgival, $g_pro, $g_show,$config;

	$site_id = admin::admin_get_user_site_id();
	
	$db_food_album = new db_food_album();
	$data = $db_food_album->admin_get_food_album_by_ids(array($g_cgival['album_id']));
	if(!empty($data[0]))
	{
		$album_info = $data[0];
		
		$db_food_album_tag = new db_food_album_tag();
		$tags_tmp = $db_food_album_tag->admin_get_tags_by_album_id($g_cgival['album_id']);
		$album_info['tag'] = $tags_tmp;
		foreach ($album_info['tag'] as $tag) {
			$album_info['tag_str'] .= $tag['tag'].' ';
		}
		$album_info['tag_str'] = rtrim($album_info['tag_str']);

		// 跳转到前台的url
		$user_global_config =  user_global_config::get_instance();
		$domain = $user_global_config->get_domain_by_site_id($album_info["site_id"]);
		$album_info["album_url"] = "http://{$domain}/album/detail-{$album_info["album_id"]}.html";
		
		$g_show['data'] = $album_info;
		
		$mod_food_album = new mod_food_album();

		$g_show['album_class_list'] = $mod_food_album ->get_food_album_tag_list();
	
	}
	else
	{
		throw new Exception('该专辑不存在或已被删除');
	}
}

$g_show["error"] = 0;
$g_show["errmsg"] = '';
try
{
	admin_check_login();
// 	admin_check_user_priv("foodv2/album_list.php");
	check_cgi_pro();
	get_data();
	$g_show["error"] = 0;
	$g_show["errmsg"] = '';
}
catch(Exception $e)
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
}

show_pro();
exit;


function show_pro()
{
	global $g_cgival, $g_pro, $g_show;
	
	if(isset($_GET['debug']))
		print_r($g_show);
	
	$smarty = p_get_smarty ();
	$smarty->assign ( 'g_show', $g_show );
	if ($g_show["error"] == 1)
	{
		$smarty->display("admin_error.html");
		return;
	}
	$smarty->display ( "foodv2/album/edit_album.html" );
}
?>